package com.cskaoyan._14network._04test._01moresandre;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author Macro_Ray
 * @since 2024/3/26 10:11
 */
// 服务器：接受多次数据，并打印
public class Server {
    public static void main(String[] args) throws IOException {
        // 1.创建 ServerSocket对象，绑定端口
        ServerSocket ss = new ServerSocket(10086);

        // 2.监听客户端连接，等待数据
        Socket socket = ss.accept();
        // 3.获取输入流，读数据
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        int b =0;
        while ((b = br.read())!= -1) {
            System.out.print((char) b);
        }
        // 4.释放资源
        socket.close();
        ss.close();
    }
}
